package huawei0814;

import java.util.HashMap;
import java.util.Scanner;

/**
 * Created by JiaJia on 2019/8/28 0028.
 */
public class MatrixNeighbour {
    private final static int[][] arr={{1,2,3,4,5},{11,12,13,14,15},{21,22,23,24,25},{31,32,33,34,35},{41,42,43,44,45}};
    private final static int[][] direction={{1,0},{-1,0},{0,1},{0,-1}};
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        while (scanner.hasNext()){
            int[] nums=new int[6];
            for (int i = 0; i <6 ; i++) {
                nums[i]=scanner.nextInt();
            }
            System.out.println(judgeNeighbour(arr,nums));
        }
        scanner.close();
    }
    private static int judgeNeighbour(int[][] arr,int[] nums){
        HashMap<Integer,Integer> map=new HashMap<>(6);
        for(int i=0;i<6;i++){
            map.put(nums[i],1);
        }
        if (nums==null || nums.length==0){
            return 1;
        }
        boolean[][] hasVisited=new boolean[5][5];

        for (int r = 0; r <5 ; r++) {
            for (int c = 0; c <5 ; c++) {
                if (backtracking(0,r,c,hasVisited,arr,nums,map)){
                    return 1;
                }
            }
        }
        return 0;
    }
    private static boolean backtracking(int len,int r,int c,boolean[][] visited,int[][] arr,int[] nums,HashMap<Integer,Integer> map){
        if (len==nums.length){
            return true;
        }
        if (r<0||r>=5||c<0||c>=5||!map.containsKey(arr[r][c])||visited[r][c]){
            return false;
        }
        visited[r][c]=true;
        for (int[] d:direction) {
            if (backtracking(len+1,r+d[0],c+d[1],visited,arr,nums,map)){
                return true;
            }
        }
        visited[r][c]=false;

        return false;
    }
}

 /*private static int judgeNrighbour(int[][] arr,int[] nums){
        HashMap<Integer,Integer> map=new HashMap<>();
        for(int i=0;i<6;i++){
            map.put(nums[i],1);
        }
        int result=0;
        for (int i = 0; i <5; i++) {
            for (int j = 0; j <5 ; j++) {
                dfs(arr,i,j,map);
                result++;
            }
        }
        return result;
    }
    private static void dfs(int[][] arr,int i,int j,HashMap<Integer,Integer> map){
        if (i<0||i>=5||j<0||j>=5||arr[i][j]==0||map.get(arr[i][j])!=1){
            return;
        }
        arr[i][j]=0;
        for(int[] d:direction){
            dfs(arr,i+d[0],j+d[1],map);
        }
    }*/